#include <iostream>
using namespace std;

//version 1 使用数电中全加器的思路
class Solution {
public:
    int getSum(int a, int b) {
        int next = 0, cur = 0, ans = 0;
        for(int i = 0; i < 32; ++i){
            int a_ibit = (a >> i) & 1, b_ibit = (b >> i) & 1;
            cur = (a_ibit ^ b_ibit) ^ next;
            if(cur) ans |= (cur << i);
            next = (a_ibit & b_ibit) || ((a_ibit ^ b_ibit) & next);
        }
        return ans;
    }
};




//version 2
//利用异或做一次半加 ，然后算一次进位(注意进位算的是高一位的进位)
//最后，直接在进行一次异或做半加即可！
//然后一直算到没有进位即可！

class Solution {
public:
    int getSum(int a, int b) {
        while(b){
            unsigned int carry = (a & b) << 1;
            a = a ^ b;
            b = carry;
        }
        return a;
    }
};



//上面两种思路都可以